<template>
  <div>
    <el-row>
      <el-col>
        <el-button @click="$router.back()">返回</el-button>
        <span style="font-size: 20px; margin-left: 10px">司机详情</span>
      </el-col>
    </el-row>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="基本信息" name="first">
        <el-form :inline="true" :model="form" class="demo-form">
          <el-form-item label="员工编号：" style="width: 370px">
            <el-input
                v-model="form.userId"
                placeholder="员工编号："
                disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="司机名称：" style="width: 370px">
            <el-input
                v-model="form.name"
                placeholder="司机名称："
                disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="所属机构：" style="width: 370px">
            <el-input
                v-model="form.agency.name"
                placeholder="所属机构："
                disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="电话" style="width: 370px">
            <el-input
                v-model="form.mobile"
                placeholder="电话"
                disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="年龄" style="width: 370px">
            <el-input
                v-model="form.age"
                placeholder="年龄"
                :disabled="disabled"
            >
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="edit" v-if="disabled"
            >编辑</el-button
            >
            <div v-else>
              <el-button type="primary" @click="save">保存</el-button>
              <el-button type="primary" @click="cancel">取消</el-button>
            </div>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <!-- 驾驶证 -->
      <el-tab-pane label="驾驶证信息" name="second">
        <el-form :inline="true">
          <el-form-item label="驾驶证号" style="width: 370px">
            <el-input
                v-model="formData.licenseNumber"
                placeholder="驾驶证号"
                :disabled="disabledData"
            ></el-input>
          </el-form-item>
          <el-form-item label="准驾车型：" style="width: 370px">
            <el-input
                v-model="formData.allowableType"
                placeholder="准驾车型："
                :disabled="disabledData"
            ></el-input>
          </el-form-item>
          <el-form-item label="初次领证日期：" style="width: 370px">
            <el-date-picker
                v-model="formData.initialCertificateDate"
                type="date"
                placeholder="选择日期"
                @change="time"
                value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="驾驶证有效期限：" style="width: 370px">
            <el-input
                v-model="formData.validPeriod"
                placeholder="驾驶证有效期限："
                :disabled="disabledData"
            ></el-input>
          </el-form-item>
          <el-form-item label="驾龄：" style="width: 370px">
            <el-input
                v-model="formData.driverAge"
                placeholder="驾龄："
                :disabled="disabledData"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="驾驶证类型：" style="width: 370px">
            <el-input
                v-model="formData.licenseType"
                placeholder="驾驶证类型："
                :disabled="disabledData"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="从业资格证" style="width: 370px">
            <el-input
                v-model="formData.qualificationCertificate"
                placeholder="从业资格证"
                :disabled="disabledData"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="入场证信息：" style="width: 370px">
            <el-input
                v-model="formData.passCertificate"
                placeholder="入场证信息："
                :disabled="disabledData"
            >
            </el-input>
          </el-form-item>
        </el-form>
        <!-- img -->
        <div class="img">
          <span style="font-size: 20px">图片</span>
          <div v-if="disabledData">
          </div>
          <el-upload
              action="#"
              list-type="picture-card"
              :file-list="fileList"
              :on-remove="removeImg"
              :on-change="changImg"
              :http-request="upload"
              v-else
          >
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </div>
        <div>
          <el-button type="primary" @click="editData" v-if="disabledData"
          >编辑</el-button
          >
          <div v-else>
            <el-button type="primary" @click="saveData">保存</el-button>
            <el-button type="primary" @click="cancelData">取消</el-button>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {baocuninfoApi, getdetailApi, getdriveinfoApi} from "@/api/drive";

export default {
  data() {
    return {
      activeName: 'first',
      form: {
        userId: "",
        name: "",
        agency: {},
        mobile: "",
        age: "",
      },
      formData: {
        licenseNumber: "",
        allowableType: "",
        initialCertificateDate: "",
        validPeriod: "",
        driverAge: "",
        licenseType: "",
        qualificationCertificate: "",
        passCertificate: "",
        picture: [],
        userId: "",
      },
      disabled: true,
      disabledData: true,
      fileList: [],
    };
  },
  created() {
  },
  methods: {
    //切换tab页
   async  handleClick() {
      if(this.activeName==='second') {
        const res = await getdriveinfoApi(this.$route.query.id)
        this.formData=res.data
      }else {
        const res =await getdetailApi(this.$route.query.id)
        console.log(res)
        this.form=res.data
      }

    },
    edit() {
      // console.log(this.$route.query.id)
this.disabled=false
    },

    time() {

    },
    editData() {
      this.disabledData=false
    },
    saveData() {

    },
    async save() {
      console.log(this.$route.query.id)
const res = await baocuninfoApi(this.$route.query.id,this.form)
      console.log(res)
    },
    cancel() {

    },
    removeImg() {

    },
    changImg() {

    },
    upload() {

    },
    cancelData() {

    },
    click() {}
}}
</script>

<style lang="scss" scoped>
.el-tabs.el-tabs--top {
  padding: 30px;
  min-height: 500px;
  background-color: #fff;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
